const express = require("express")
const app = express();
const path = require("path");
app.use("/", express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
    res.redirect('/index.html');
})
app.get("/api/all", (req, res) => {
    const FilesJson = require("./getAllFiles")
    const filesLength = FilesJson.length
    res.json({
        code: 200,
        length: filesLength,
        data: FilesJson
    })
})
app.get("/select", (req, res) => {
    const FilesJson = require("./getAllFiles")
    let userSelect = ".pdf"
    let newArr = []
    FilesJson.map((v) => {
        if (v.extension === userSelect) {
            newArr.push(v)
        }
    })
    let data = newArr
    const filesLength = data.length

    res.json({
        code: 200,
        length: filesLength,
        data: data
    })
})
app.listen(3000, () => {
    console.log(`listening in 3000`)
})